# 指定目标系统
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)

# 指定交叉编译器路径
set(TOOLCHAIN_DIR "/home/fairy/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package/SDK/sysroots/x86_64-ostl_sdk-linux/usr/bin/arm-ostl-linux-gnueabi")
set(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}/arm-ostl-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/arm-ostl-linux-gnueabi-g++)

# 指定sysroot路径（关键步骤）
set(CMAKE_SYSROOT "/home/fairy/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package/SDK/sysroots/cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi")
set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})

# 确保编译器在sysroot中查找库和头文件
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

# 添加必要的编译/链接选项
add_compile_options(--sysroot=${CMAKE_SYSROOT} -mthumb -mfpu=neon-vfpv4 -mfloat-abi=hard -mcpu=cortex-a7)
add_compile_options(-O2 -pipe -g -feliminate-unused-debug-types)
add_link_options(--sysroot=${CMAKE_SYSROOT} -L${CMAKE_SYSROOT}/usr/lib -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed)
